package com.uniview.config;

import com.uniview.constants.CommonConstants;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * created by lux
 * 网关feign拦截器处理
 */
@Slf4j
@Configuration
public class GatewayFeignInterceptor implements RequestInterceptor{
    @Autowired
    RedisTemplate redisTemplate;

    @Override
    public void apply(RequestTemplate requestTemplate) {
        //获取请求request
        requestTemplate.header(CommonConstants.X_REQUEST_ID, (String) redisTemplate.opsForValue().get(CommonConstants.X_REQUEST_ID));
        log.info("GatewayFeignInterceptor:{}"+requestTemplate.toString());
    }
}
